package com.example.date;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

public class TimeZone {

    static DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    public static void main(String[] args) {
        setLong();
        //获取当前时间属于周几
        LocalDateTime date = LocalDateTime.of(2024, 6, 12, 12, 00, 00);

        Instant instant = Instant.ofEpochMilli(System.currentTimeMillis());
        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant , ZoneId.systemDefault());

        Long tt = LocalDateTime.parse("2024-06-13 12:00:00", FORMATTER).toEpochSecond(ZoneOffset.UTC);
        LocalDateTime dd = LocalDateTime.ofEpochSecond(tt * 1000 / 1000,
                0, ZoneOffset.ofHours(8));
        System.out.println(dd);
    }

    public static void setLong(){
        LocalDateTime dd = LocalDateTime.parse("2024-06-13 12:00:00", FORMATTER);
        Long tt = dd.toInstant(java.util.TimeZone.getDefault().toZoneId().getRules()
                .getOffset(dd)).toEpochMilli();

        System.out.println(tt);
    }
}
